/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookshare;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Kathi & Michal & Paul
 */
@WebServlet(name = "SucheServlet", urlPatterns = {"/SucheServlet"})
public class SucheServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    public SucheServlet () {
        super();
    }
    

        
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        response.setContentType("text/html;charset=UTF-8");

        HttpSession session = request.getSession(true);
        SQLabfrage abfrage = new SQLabfrage();
        String artikelName = request.getParameter("artikelName");
        artikelName = artikelName.toLowerCase();

        ArrayList BuecherNameSuche=abfrage.sucheBuchName(artikelName);
        ArrayList SkripteNameSuche=abfrage.sucheSkriptName(artikelName);
        ArrayList SoftwareNameSuche=abfrage.sucheSoftwareName(artikelName);

        session.setAttribute("BuecherNameSuche", BuecherNameSuche);
        session.setAttribute("SkripteNameSuche", SkripteNameSuche);
        session.setAttribute("SoftwareNameSuche", SoftwareNameSuche);
        response.sendRedirect("index.jsp?param1=products&param2=suche");
    }
}
